<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>centos 部署多个tomcat并systemd控制 | FFing</title><meta name="author" content="FFing"><meta name="copyright" content="FFing"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="tomcat包是绿色文件，所以以包的方式部署win和linux集群的方式是一样的，唯一需要更改的就是server.xml端口（保障端口不冲突），就实现了集群。 我的脚本： bash &lt;(curl https:&#x2F;&#x2F;gitee.com&#x2F;ffing&#x2F;onekey&#x2F;raw&#x2F;master&#x2F;onekey.sh)  第一种方法：快捷方式win集群：复制N个包，修改N个server.xml端口，创建N对快捷">
<meta property="og:type" content="article">
<meta property="og:title" content="centos 部署多个tomcat并systemd控制">
<meta property="og:url" content="https://blog.ffing.fun/posts/20211118115517-65c613e1.html">
<meta property="og:site_name" content="FFing">
<meta property="og:description" content="tomcat包是绿色文件，所以以包的方式部署win和linux集群的方式是一样的，唯一需要更改的就是server.xml端口（保障端口不冲突），就实现了集群。 我的脚本： bash &lt;(curl https:&#x2F;&#x2F;gitee.com&#x2F;ffing&#x2F;onekey&#x2F;raw&#x2F;master&#x2F;onekey.sh)  第一种方法：快捷方式win集群：复制N个包，修改N个server.xml端口，创建N对快捷">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-11-18T03:55:17.000Z">
<meta property="article:modified_time" content="2023-01-25T10:48:56.000Z">
<meta property="article:author" content="FFing">
<meta property="article:tag" content="centos">
<meta property="article:tag" content="tomcat">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="systemd">
<meta property="article:tag" content="tomcat集群">
<meta name="twitter:card" content="summary"><link rel="shortcut icon" href="https://src.ffing.cn/hexo/img/fn_logo_32x32.png"><link rel="canonical" href="https://blog.ffing.fun/posts/20211118115517-65c613e1"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdnjs.cloudflare.com/ajax/libs/flickr-justified-gallery/2.1.2/fjGallery.min.js',
      css: 'https://cdnjs.cloudflare.com/ajax/libs/flickr-justified-gallery/2.1.2/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'centos 部署多个tomcat并systemd控制',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-01-25 18:48:56'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/gundongtiao.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/custom.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/auth_icon.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/home_file_list.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/full_page.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/universe.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/nav_menu.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/txmap.css"><link rel="stylesheet" href="//at.alicdn.com/t/c/font_3830672_5bphzb91mjp.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/foot.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/aside.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/other_page.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/loading_bar.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/loading_gif.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/copyright.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/right_down_button.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/mouse.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/page_bg.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/lightlight.css"><link rel="stylesheet" href="https://src.ffing.cn/hexo/css/51la.css"><script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script><script src="https://sdk.51.la/perf/js-sdk-perf.min.js" crossorigin="anonymous"></script><script> LA.init({id:"JwsAbeTPm16yxMNJ",ck:"JwsAbeTPm16yxMNJ"})</script><script>new LingQue.Monitor().init({id:"JwsAbeTPm16yxMNJ",sendSuspicious:true});</script><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.min.css"/>
<style>#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags:before {content:"\A";
  white-space: pre;}#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags > .article-meta__separator{display:none}</style>
<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box" onclick="document.getElementById(&quot;loading-box&quot;).classList.add(&quot;loaded&quot;)"><div class="loading-bg"><div class="loading-img"></div><div class="loading-image-dot"></div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/blue/pace-theme-minimal.min.css"/><script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js"></script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">10</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">23</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/archives/"><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/timeline/"><span> 更新</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog_name"><div class="back-home-button" tabindex="-1"><i class="back-home-button-icon fas fa-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">网页</div><div class="back-menu-list"><a class="back-menu-item" href="https://www.ffing.cn" title="前往首页" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://src.ffing.cn/hexo/img/fn_white_logo.png"/><span class="back-menu-item-text">首页</span></a><a class="back-menu-item" href="http://pan.ffing.cn/" rel="external nofollow" title="前往alist网盘" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://src.ffing.cn/hexo/img/alist_logo.png"/><span class="back-menu-item-text">alist网盘</span></a><a class="back-menu-item" href="https://kms.ffing.cn/" rel="external nofollow" title="前往kms服务" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://src.ffing.cn/hexo/img/kms_logo.png"/><span class="back-menu-item-text">kms服务</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">在线工具</div><div class="back-menu-list"><a class="back-menu-item" href="https://www.iconfont.cn" rel="noopener nofollow" title="前往阿里icon" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://src.ffing.cn/hexo/img/ali-icon_logo.png"/><span class="back-menu-item-text">阿里icon</span></a></div></div></div></div><a id="site-name" href="/"><div class="title">FFing</div><i class="fa-solid fa-house"></i></a></span><div class="mask-name-container"><center id="name-container"><a id="page-name" href="javascript:btf.scrollToDest(0, 500)">PAGE_NAME</a></center></div><div id="weather"></div><div id="tp-weather-widget"></div> <div id="menus"><div class="nav-button" id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="nav-button" id="darkmode_navswitch"><a class="darkmode_switchbutton" type="button" title="浅色和深色模式转换" onclick="switchDarkMode()"><i class="fas fa-adjust"></i></a></div><div class="nav-button" id="nav-totop"><a class="totopbtn"><i class="fas fa-arrow-up"></i><span id="percent" onclick="btf.scrollToDest(0,500)">0</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/archives/"><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/timeline/"><span> 更新</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">centos 部署多个tomcat并systemd控制</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-11-18T03:55:17.000Z" title="发表于 2021-11-18 11:55:17">2021-11-18</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-01-25T10:48:56.000Z" title="更新于 2023-01-25 18:48:56">2023-01-25</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Linux/">Linux</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%95%99%E7%A8%8B/">教程</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1609</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>7分钟</span></span></div></div></div><article class="post-content" id="article-container"><p>tomcat包是绿色文件，所以以包的方式部署win和linux集群的方式是一样的，唯一需要更改的就是server.xml端口（保障端口不冲突），就实现了集群。</p>
<p>我的脚本：</p>
<p>bash &lt;(curl <a target="_blank" rel="noopener" href="https://gitee.com/ffing/onekey/raw/master/onekey.sh">https://gitee.com/ffing/onekey/raw/master/onekey.sh</a>)</p>
<p><img src="https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-83.png"></p>
<h2 id="第一种方法：快捷方式"><a href="#第一种方法：快捷方式" class="headerlink" title="第一种方法：快捷方式"></a>第一种方法：快捷方式</h2><p>win集群：复制N个包，修改N个server.xml端口，创建N对快捷方式到桌面（start.bat、shutodwn.bat）</p>
<p>linux集群：复制N个包，修改N个server.xml端口，创建N对软链接到&#x2F;usr&#x2F;bin下(start.sh、shutdown.sh)</p>
<p>这种快捷方式部署的方式，效率很高，什么也不用配置，创建快捷方式就OK，但后期管理就很不方便了（譬如上个zabbix，脚本就需要再根据情况编写）</p>
<h2 id="第二种方法：配置环境变量"><a href="#第二种方法：配置环境变量" class="headerlink" title="第二种方法：配置环境变量"></a>第二种方法：配置环境变量</h2><p>配置环境变量，就可以实现systemd进行控制。</p>
<h4 id="流程："><a href="#流程：" class="headerlink" title="流程："></a>流程：</h4><ul>
<li>下载安装tomcat</li>
<li>配置环境变量</li>
<li>更新tomcat变量</li>
<li>修改tomcat访问端口</li>
<li>防火墙放行端口</li>
<li>创建systemd服务文件</li>
<li>测试</li>
</ul>
<p>本次集群以3个tomcat8为例：</p>
<p>（为了不影响原有tomcat，分别命名tomcat1、tomcat2、tomcat3）</p>
<ul>
<li>tomcat1：&#x2F;usr&#x2F;local&#x2F;tomcat-group&#x2F;tomcat-8_1（路径及变量加_1，端口81xx）</li>
<li>tomcat2：&#x2F;usr&#x2F;locat&#x2F;tomcat-group&#x2F;tomcat-8_2（路径及变量加_2，端口82xx）</li>
<li>tomcat3：&#x2F;usr&#x2F;local&#x2F;tomcat-group&#x2F;tomcat-8_3（路径及变量加_3，端口83xx）</li>
</ul>
<h4 id="1-下载tomcat，安装到-x2F-usr-x2F-local"><a href="#1-下载tomcat，安装到-x2F-usr-x2F-local" class="headerlink" title="1.下载tomcat，安装到&#x2F;usr&#x2F;local"></a>1.下载tomcat，安装到&#x2F;usr&#x2F;local</h4><p>（我前面有详写：<a target="_blank" rel="noopener" href="https://blog.ffing.cn/linux/centos-%e5%ae%89%e8%a3%85tomcat%e5%b9%b6systemctl%e6%8e%a7%e5%88%b6">centos安装tomcat</a>）</p>
<p>官网下载：<a target="_blank" rel="noopener" href="http://tomcat.apache.org/">http://tomcat.apache.org/</a></p>
<p><img src="https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-68.png"></p>
<p>下载tomcat，并复制2个tomcat包，并重命名</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">#安装wget（如已安装可以忽略）</span><br><span class="line">yum -y install wget</span><br><span class="line">#下载tomcat并重命名为tomcat-8.tar.gz（地址可能失效，请官网更新）</span><br><span class="line">wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.73/bin/apache-tomcat-8.5.73.tar.gz --no-check-certificate -O tomcat-8.tar.gz</span><br><span class="line">#解压（解压后的文件名需要更改为tomcat-8）</span><br><span class="line">mkdir ./tomcat-8 &amp;&amp; tar -xvf tomcat-8.tar.gz  -C ./tomcat-8 --strip-components 1</span><br><span class="line">#创建/usr/local/tomcat-group目录</span><br><span class="line">mkdir /usr/local/tomcat-group</span><br><span class="line">#重命名为tomcat8_1</span><br><span class="line">cp -r tomcat-8 /usr/local/tomcat-group/tomcat-8_1</span><br><span class="line">#复制出第二个tomcat-8_2</span><br><span class="line">cp -r tomcat-8 /usr/local/tomcat-group/tomcat-8_2</span><br><span class="line">#复制出第三个tomcat-8_3</span><br><span class="line">cp -r tomcat-8 /usr/local/tomcat-group/tomcat-8_3</span><br></pre></td></tr></table></figure>

<h4 id="2-配置环境变量"><a href="#2-配置环境变量" class="headerlink" title="2.配置环境变量"></a>2.配置环境变量</h4><p>注：tomcat需java环境请提前安装！</p>
<p>编辑&#x2F;etc&#x2F;profile（如仅限本用户使用，修改家目录下.bash_profile）加如下变量</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">#tomcat_1环境变量</span><br><span class="line">export TOMCAT_HOME_1=/usr/local/tomcat-group/tomcat-8_1</span><br><span class="line">export CATALINA_HOME_1=$TOMCAT_HOME_1</span><br><span class="line">export CATLINA_BASE_1=$TOMCAT_HOME_1</span><br><span class="line"></span><br><span class="line">#tomcat_2环境变量</span><br><span class="line">export TOMCAT_HOME_2=/usr/local/tomcat-group/tomcat-8_2</span><br><span class="line">export CATALINA_HOME_2=$TOMCAT_HOME_2</span><br><span class="line">export CATLINA_BASE_2=$TOMCAT_HOME_2</span><br><span class="line"></span><br><span class="line">#tomcat_3环境变量</span><br><span class="line">export TOMCAT_HOME_3=/usr/local/tomcat-group/tomcat-8_3</span><br><span class="line">export CATALINA_HOME_3=$TOMCAT_HOME_3</span><br><span class="line">export CATLINA_BASE_3=$TOMCAT_HOME_3</span><br></pre></td></tr></table></figure>

<p>环境变量生效:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source /etc/profile</span><br></pre></td></tr></table></figure>

<h4 id="3-更新tomcat变量"><a href="#3-更新tomcat变量" class="headerlink" title="3.更新tomcat变量"></a>3.更新tomcat变量</h4><p>将刚配置的环境变量加入到对应的tomcat*&#x2F;bin&#x2F;catalina.sh中</p>
<p>tomcat1：vi &#x2F;usr&#x2F;local&#x2F;tomcat-group&#x2F;tomcat-8_1&#x2F;bin&#x2F;catalina.sh</p>
<p>在#&#x2F;bin&#x2F;bash下追加环境变量：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#tomcat_1环境变量</span><br><span class="line">export TOMCAT_HOME_1=/usr/local/tomcat-group/tomcat-8_1</span><br><span class="line">export CATALINA_HOME_1=$TOMCAT_HOME_1</span><br><span class="line">export CATLINA_BASE_1=$TOMCAT_HOME_1</span><br></pre></td></tr></table></figure>

<p>tomcat2：vi &#x2F;usr&#x2F;local&#x2F;tomcat-group&#x2F;tomcat-8_2&#x2F;bin&#x2F;catalina.sh</p>
<p>在#&#x2F;bin&#x2F;bash下追加环境变量：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#tomcat_2环境变量</span><br><span class="line">export TOMCAT_HOME_2=/usr/local/tomcat-group/tomcat-8_2</span><br><span class="line">export CATALINA_HOME_2=$TOMCAT_HOME_2</span><br><span class="line">export CATLINA_BASE_2=$TOMCAT_HOME_2</span><br></pre></td></tr></table></figure>

<p>tomcat3：vi &#x2F;usr&#x2F;local&#x2F;tomcat-group&#x2F;tomcat-8_3&#x2F;bin&#x2F;catalina.sh</p>
<p>在#&#x2F;bin&#x2F;bash下追加环境变量：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#tomcat_3环境变量</span><br><span class="line">export TOMCAT_HOME_3=/usr/local/tomcat-group/tomcat-8_3</span><br><span class="line">export CATALINA_HOME_3=$TOMCAT_HOME_3</span><br><span class="line">export CATLINA_BASE_3=$TOMCAT_HOME_3</span><br></pre></td></tr></table></figure>

<h4 id="4-修改tomcat访问端口"><a href="#4-修改tomcat访问端口" class="headerlink" title="4.修改tomcat访问端口"></a>4.修改tomcat访问端口</h4><p>修改server.xml文件，保障端口不冲突，才可以每个tomcat正常访问。</p>
<p><img src="https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-81.png"></p>
<p>tomcat1：编辑 &#x2F;usr&#x2F;local&#x2F;tomcat-group&#x2F;tomcat-8_1&#x2F;conf&#x2F;server.xml</p>
<p>8005端口：改为8105 8080端口：改为8180 8009端口：改为8109</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sed -i &#x27;s/port=&quot;8080&quot;/port=&quot;8180&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_1/conf/server.xml</span><br><span class="line">sed -i &#x27;s/port=&quot;8005&quot;/port=&quot;8105&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_1/conf/server.xml</span><br><span class="line">sed -i &#x27;s/port=&quot;8009&quot;/port=&quot;8109&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_1/conf/server.xml</span><br></pre></td></tr></table></figure>

<p>tomcat2：编辑 &#x2F;usr&#x2F;local&#x2F;tomcat-group&#x2F;tomcat-8_2&#x2F;conf&#x2F;server.xml</p>
<p>8005端口：改为8205 8080端口：改为8280 8009端口：改为8209</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sed -i &#x27;s/port=&quot;8080&quot;/port=&quot;8280&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_2/conf/server.xml</span><br><span class="line">sed -i &#x27;s/port=&quot;8005&quot;/port=&quot;8205&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_2/conf/server.xml</span><br><span class="line">sed -i &#x27;s/port=&quot;8009&quot;/port=&quot;8209&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_2/conf/server.xml</span><br></pre></td></tr></table></figure>

<p>tomcat3：编辑 &#x2F;usr&#x2F;local&#x2F;tomcat-group&#x2F;tomcat-8_3&#x2F;conf&#x2F;server.xml</p>
<p>8005端口：改为8305 8080端口：改为8380 8009端口：改为8309</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sed -i &#x27;s/port=&quot;8080&quot;/port=&quot;8380&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_3/conf/server.xml</span><br><span class="line">sed -i &#x27;s/port=&quot;8005&quot;/port=&quot;8305&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_3/conf/server.xml</span><br><span class="line">sed -i &#x27;s/port=&quot;8009&quot;/port=&quot;8309&quot;/g&#x27; /usr/local/tomcat-group/tomcat-8_3/conf/server.xml</span><br></pre></td></tr></table></figure>

<h4 id="5-防火墙放行端口"><a href="#5-防火墙放行端口" class="headerlink" title="5.防火墙放行端口"></a>5.防火墙放行端口</h4><p>放行3个tomcat对应的端口</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">#放行tomcat1：8180</span><br><span class="line">firewall-cmd --add-port=8180/tcp --zone=public --permanent</span><br><span class="line">#放行tomcat2：8280</span><br><span class="line">firewall-cmd --add-port=8280/tcp --zone=public --permanent</span><br><span class="line">#放行tomcat3：8380</span><br><span class="line">firewall-cmd --add-port=8380/tcp --zone=public --permanent</span><br><span class="line">#重新加载防火墙</span><br><span class="line">firewall-cmd --reload</span><br></pre></td></tr></table></figure>

<h4 id="6-创建systemd服务文件"><a href="#6-创建systemd服务文件" class="headerlink" title="6.创建systemd服务文件"></a>6.创建systemd服务文件</h4><p>创建systemd服务文件，实现systemctl控制</p>
<p>创建3个tomcat服务文件，tomcat1.service、tomcat2.service、tomcat3.service,分别对应各自的路径文件。</p>
<p>tomcat1：vi &#x2F;usr&#x2F;lib&#x2F;systemd&#x2F;system&#x2F;tomcat1.service</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description=tomcat-8_1</span><br><span class="line">After=network.target</span><br><span class="line"> </span><br><span class="line">[Service]</span><br><span class="line">Type=forking</span><br><span class="line">ExecStart=/usr/local/tomcat-group/tomcat-8_1/bin/startup.sh</span><br><span class="line">ExecStop=/usr/local/tomcat-group/tomcat-8_1/bin/shutdown.sh</span><br><span class="line">ExecReload=/bin/kill -s HUP $MAINPID</span><br><span class="line">PrivateTmp=ture</span><br><span class="line">Restart=always</span><br><span class="line"> </span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br></pre></td></tr></table></figure>

<p>tomcat2：vi &#x2F;usr&#x2F;lib&#x2F;systemd&#x2F;system&#x2F;tomcat2.service</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description=tomcat-8_2</span><br><span class="line">After=network.target</span><br><span class="line"> </span><br><span class="line">[Service]</span><br><span class="line">Type=forking</span><br><span class="line">ExecStart=/usr/local/tomcat-group/tomcat-8_2/bin/startup.sh</span><br><span class="line">ExecStop=/usr/local/tomcat-group/tomcat-8_2/bin/shutdown.sh</span><br><span class="line">ExecReload=/bin/kill -s HUP $MAINPID</span><br><span class="line">PrivateTmp=ture</span><br><span class="line">Restart=always</span><br><span class="line"> </span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br></pre></td></tr></table></figure>

<p>tomcat3：vi &#x2F;usr&#x2F;lib&#x2F;systemd&#x2F;system&#x2F;tomcat3.service</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description=tomcat-8_3</span><br><span class="line">After=network.target</span><br><span class="line"> </span><br><span class="line">[Service]</span><br><span class="line">Type=forking</span><br><span class="line">ExecStart=/usr/local/tomcat-group/tomcat-8_3/bin/startup.sh</span><br><span class="line">ExecStop=/usr/local/tomcat-group/tomcat-8_3/bin/shutdown.sh</span><br><span class="line">ExecReload=/bin/kill -s HUP $MAINPID</span><br><span class="line">PrivateTmp=ture</span><br><span class="line">Restart=always</span><br><span class="line"> </span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br></pre></td></tr></table></figure>

<p>重新加载服务</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl daemon-reload</span><br></pre></td></tr></table></figure>

<h4 id="7-测试"><a href="#7-测试" class="headerlink" title="7.测试"></a>7.测试</h4><p>为了方便区分3个tomcat内容，分别向第二个，和第三个tomcat主页加入自己tomcat名称</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">#第一个tomcat主页，body标签下加入“这是tomcat1”</span><br><span class="line">sed -i &#x27;/&lt;body&gt;/a 这是tomcat1&#x27; /usr/local/tomcat-group/tomcat-8_1/webapps/ROOT/index.jsp</span><br><span class="line">#第二个tomcat主页，body标签下加入“这是tomcat2”</span><br><span class="line">sed -i &#x27;/&lt;body&gt;/a 这是tomcat2&#x27; /usr/local/tomcat-group/tomcat-8_2/webapps/ROOT/index.jsp</span><br><span class="line">#第三个tomcat主页，body标签下加入“这是tomcat3”</span><br><span class="line">sed -i &#x27;/&lt;body&gt;/a 这是tomcat3&#x27; /usr/local/tomcat-group/tomcat-8_3/webapps/ROOT/index.jsp</span><br></pre></td></tr></table></figure>

<p>重启3个tomcat：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#懒人一次重启3个（当然你也可以单独启动每一个，进行测试）</span><br><span class="line">systemctl restart tomcat1 tomcat2 tomcat3</span><br></pre></td></tr></table></figure>

<p><img src="https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-86.png"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://blog.ffing.fun">FFing</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://blog.ffing.fun/posts/20211118115517-65c613e1.html">https://blog.ffing.fun/posts/20211118115517-65c613e1.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://blog.ffing.fun" target="_blank">FFing</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/centos/">centos</a><a class="post-meta__tags" href="/tags/tomcat/">tomcat</a><a class="post-meta__tags" href="/tags/linux/">linux</a><a class="post-meta__tags" href="/tags/systemd/">systemd</a><a class="post-meta__tags" href="/tags/tomcat%E9%9B%86%E7%BE%A4/">tomcat集群</a></div><div class="post_share"><div class="social-share" data-image="" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://lib.baomitu.com/social-share.js/1.0.16/css/share.min.css" media="print" onload="this.media='all'"><script src="https://lib.baomitu.com/social-share.js/1.0.16/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/20211221153232-4c7d71f9.html"><img class="prev-cover" src="" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">centos 搭建本地yum源、网络yum源</div></div></a></div><div class="next-post pull-right"><a href="/posts/20211117165540-93d10bf1.html"><img class="next-cover" src="" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">centos 安装tomcat并systemctl控制</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/20211117165540-93d10bf1.html" title="centos 安装tomcat并systemctl控制"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-17</div><div class="title">centos 安装tomcat并systemctl控制</div></div></a></div><div><a href="/posts/20211102152601-2853445c.html" title="centos 7 重置root密码"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-02</div><div class="title">centos 7 重置root密码</div></div></a></div><div><a href="/posts/20211115220453-26cdf4b7.html" title="centos 搭建ftp(匿名+本地用户)"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-15</div><div class="title">centos 搭建ftp(匿名+本地用户)</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%B8%80%E7%A7%8D%E6%96%B9%E6%B3%95%EF%BC%9A%E5%BF%AB%E6%8D%B7%E6%96%B9%E5%BC%8F"><span class="toc-number">1.</span> <span class="toc-text">第一种方法：快捷方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%BA%8C%E7%A7%8D%E6%96%B9%E6%B3%95%EF%BC%9A%E9%85%8D%E7%BD%AE%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="toc-number">2.</span> <span class="toc-text">第二种方法：配置环境变量</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B5%81%E7%A8%8B%EF%BC%9A"><span class="toc-number">2.0.1.</span> <span class="toc-text">流程：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E4%B8%8B%E8%BD%BDtomcat%EF%BC%8C%E5%AE%89%E8%A3%85%E5%88%B0-x2F-usr-x2F-local"><span class="toc-number">2.0.2.</span> <span class="toc-text">1.下载tomcat，安装到&#x2F;usr&#x2F;local</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E9%85%8D%E7%BD%AE%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="toc-number">2.0.3.</span> <span class="toc-text">2.配置环境变量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E6%9B%B4%E6%96%B0tomcat%E5%8F%98%E9%87%8F"><span class="toc-number">2.0.4.</span> <span class="toc-text">3.更新tomcat变量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E4%BF%AE%E6%94%B9tomcat%E8%AE%BF%E9%97%AE%E7%AB%AF%E5%8F%A3"><span class="toc-number">2.0.5.</span> <span class="toc-text">4.修改tomcat访问端口</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E9%98%B2%E7%81%AB%E5%A2%99%E6%94%BE%E8%A1%8C%E7%AB%AF%E5%8F%A3"><span class="toc-number">2.0.6.</span> <span class="toc-text">5.防火墙放行端口</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6-%E5%88%9B%E5%BB%BAsystemd%E6%9C%8D%E5%8A%A1%E6%96%87%E4%BB%B6"><span class="toc-number">2.0.7.</span> <span class="toc-text">6.创建systemd服务文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7-%E6%B5%8B%E8%AF%95"><span class="toc-number">2.0.8.</span> <span class="toc-text">7.测试</span></a></li></ol></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By FFing</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div><div id="footer-banner"><div class="footer-banner-links"><div class="footer-banner-left"><div class="footer-banner-left"><div id="footer-banner-tips"></div><script src="https://src.ffing.cn/hexo/js/typed.min.foot_daziji.js"></script><script>var typed = new Typed("#footer-banner-tips", {
  strings: ["你不在正经事上忧虑,就会在乱七八糟事上忧虑,能力守恒!", "折腾硬件、软件;折腾系统、平台;折腾开发、环境;折腾window、linux;折腾,折腾,瞎J8折腾."],
  startDelay: 200,
  backDelay: 2000,
  typeSpeed: 100,
  loop: true,
  backSpeed: 20
})
</script></div></div><div class="footer-banner-right"><p><a target="_blank" href="https://hexo.io/"><img src="http://src.ffing.cn/hexo/img/Frame-Hexo-blue.svg" title="框架"></a>&nbsp;<a target="_blank" href="https://butterfly.js.org/"><img src="http://src.ffing.cn/hexo/img/Theme-Butterfly.svg" title="主题"></a>&nbsp;<a target="_blank" href="https://www.upyun.com/"><img src="http://src.ffing.cn/hexo/img/CDN又拍云.svg" title="CDN加速"></a>&nbsp;<a target="_blank" href="https://www.51.la/"><img src="http://src.ffing.cn/hexo/img/Analytics-51la.svg" title="51la统计"></a>&nbsp;<a target="_blank" href="https://www.upyun.com/"><img src="http://src.ffing.cn/hexo/img/豫ICP备2021016009.svg" title="ICP备案"></a></p></div></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.umd.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script src="https://src.ffing.cn/hexo/js/jquery.min.3.6.3.js"></script><canvas id="universe"></canvas><script defer src="https://src.ffing.cn/hexo/js/universe.js"></script><script defer src="https://src.ffing.cn/hexo/js/switchDarkMode.js"></script><script defer src="https://src.ffing.cn/hexo/js/nav_menu.js"></script><script async data-pjax src="https://src.ffing.cn/hexo/js/txmap.js"></script><script async src="//at.alicdn.com/t/c/font_3830672_5bphzb91mjp.js"></script><script src="https://src.ffing.cn/hexo/js/jquery.min.js"></script><script src="https://src.ffing.cn/hexo/js/weather.js"></script><script src="https://src.ffing.cn/hexo/js/foot_runtime.js"></script></div></body></html>